import pymysql
# 创建数据库连接
conn = pymysql.connect(
    host = "192.168.138.131",
    user = "yang",
    passwd = "123456",
    port = 3306,
    db = "test2"
)
# grant all on *.* to 'yang'@'%' identified by '123456'

# 创建游标 => 真正执行sql语句
# 开启隐形的事务 => commit才会数据提交到数据库
cur = conn.cursor()

# 先删除同名表，再创建表
sql = "DROP TABLE IF EXISTS app1"
cur.execute(sql)
sql = """CREATE TABLE app1(
    name VARCHAR(20)
)"""
cur.execute(sql)

# 先删除同名表，再创建表
sql = "DROP TABLE IF EXISTS app2"
import pymysql
# 创建数据库连接
db = pymysql.connect(
    host = "192.168.138.131",
    user = "yang",
    passwd = "123456",
    port = 3306,
    db = "test2"
)
# grant all on *.* to 'yang'@'%' identified by '123456'

#创建游标 --- 真正的执行sql语句
cur = db.cursor()

#先删除同名表，再创建表
sql = "DROP TABLE IF EXISTS product"
cur.execute(sql)

sql = """CREATE TABLE product
(
    name varchar(10) NOT NULL,
    price INT NOT NULL,
    stock INT NOT NULL
)"""
cur.execute(sql)